import xlwt
import time

def read(biao):
    biao.seek(0,1)
    while True:
        line = biao.readline()
        if not line:
            time.sleep(0.1)
            break
        yield line

class test11:
    xl = open(file=r"F:\python\test11\a.txt")

    wb = xlwt.Workbook("utf-8")
    sheet = wb.add_sheet("日志级别", cell_overwrite_ok=True)
    row0 = ["测试序号", 'W', 'I', 'D', 'E']
    for i in range(len(row0)):
        sheet.write(0, i, row0[i])

    O = 0
    while True:
        W = 0
        I = 0
        D = 0
        E = 0
        for line in read(xl):
            if len(line) > 31:
                if line[31] == "W":
                    W += 1
                elif line[31] == "I":
                    I += 1
                elif line[31] == "D":
                    D += 1
                elif line[31] == "E":
                    E += 1
        if W != 0 or I != 0 or D != 0 or E != 0:
            O += 1
            num = [O,W,I,D,E]
            for i in range(len(num)):
                sheet.write(O,i,num[i])
                wb.save(r"F:\python\test11\测试数据.xls")
            print("这是第", O, "次测试")
        time.sleep(2)



